Page({
  data:{
    tabs:[
      {id:0, value:'体验问题', isActive:true},
      {id:1, value:'商品、商家投诉', isActive:false}
    ],
    feedbackText:'',
    chooseImgsPath:[]
  },
  onChangeTabsItem(ev) {
    const {index} = ev.detail;
    let {tabs} = this.data;
    tabs.forEach((val, i, self) => i === index ? val.isActive = true : val.isActive = false);
    this.setData({tabs});
  },
  onInputFeedback(ev) {
    this.setData({feedbackText:ev.detail.value});
  },
  onTapChooseImg(ev) {
    wx.chooseImage({
      count:9,
      sizeType:['original', 'compressed'],
      sourceType:['album', 'camera'],
      success:result => {
        console.log('选择的图片', result);
        this.setData({chooseImgsPath:[...this.data.chooseImgsPath, ...result['tempFilePaths']]});
      },
      fail:err => {},
      complete:() => {}
    });
  },
  onTapRemoveImg(ev) {
    const {index} = ev.currentTarget.dataset;
    let {chooseImgsPath} = this.data;
    chooseImgsPath.splice(index, 1);
    this.setData({chooseImgsPath});
  },
  onTapSubmit(ev) {
    let {feedbackText, chooseImgsPath} = this.data;
    if (!feedbackText.trim()) {
      wx.showToast({title:'请输入您要反馈的问题', icon:'none', mask:true});
      return;
    }
    if (chooseImgsPath.length > 0) {
      return;
    } else {
      console.log('只提交反馈文本');
      wx.navigateBack({delta:1});
    }
  }
});